package com.gitee.wsl.struct.grammar.parser.token

import com.gitee.wsl.struct.grammar.parser.ParsingScope
import com.gitee.wsl.struct.grammar.parser.result.getOrElse


abstract class AbstractWarpToken(
    val base: AbstractToken
) : AbstractToken(){

    override var name: String? by base::name

    override fun toString(): String = base.toString()

    override val ignored: Boolean by base::ignored

    override val firstTokens: Set<Token> by base::firstTokens

    override val firstChars: String by base::firstChars

    override fun match(input: CharSequence, fromIndex: Int): Int = base.match(input, fromIndex)

    override fun equals(other: Any?): Boolean {
        return base == other
    }

    override fun hashCode(): Int {
        return base.hashCode()
    }

    override suspend fun ParsingScope.parse(): TokenMatch {
        return tryParse(base).getOrElse { fail(it) }
    }

}